package com.xuhuan.practice.validation.validator;

import com.xuhuan.practice.validation.annotation.ArticleState;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.apache.commons.lang3.StringUtils;

/**
 * @author: huan.xu
 * @create: 2024/6/11 22:44
 * @description: 文章状态注解校验逻辑
 **/
public class ArticleStateValidation implements ConstraintValidator<ArticleState, String> {

  /**
   * 校验规则
   *
   * @param s
   * @param constraintValidatorContext
   * @return
   */
  @Override
  public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
    if (s == null) {
      return false;
    }
    if ("已发布".equals(s) || "草稿".equals(s)) {
      return true;
    }
    return false;
  }
}
